/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Tavolo.java
 *
 * Created on 11-mar-2010, 20.12.36
 */
package blackjack.graphics;

import blackjack.Banco;
import blackjack.Carta;
import blackjack.Giocatore;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

/**
 *
 * @author paolo
 */
public class Tavolo extends javax.swing.JFrame {

    private final String estensione = ".png";
    private Banco banco;
    private int soldi;
    private Giocatore player;

    private class Tasti extends KeyAdapter implements KeyListener {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                close();
            } else if (e.getKeyCode() == KeyEvent.VK_F1) {
                newGame();
            } else if (e.getKeyCode() == KeyEvent.VK_M) {
                JOptionPane.showMessageDialog(rootPane, "Ringraziamento speciale a Mariangela, che mi ha dato l'idea del KeyListener!");
            } else if (e.getKeyCode() == KeyEvent.VK_L) {
                JOptionPane.showMessageDialog(rootPane, "Ringraziamento speciale a Lorenzo, che mi ha ispirato col suo Black Jack!l");
            }else if(e.getKeyCode()== KeyEvent.VK_O){
                JOptionPane.showMessageDialog(rootPane, "Ringraziamento speciale al prof. Oliveto Rocco che mi ha supportato e soprattutto sopportato dandomi preziosi consigli!");
            }else if(e.getKeyCode()== KeyEvent.VK_F){
                JOptionPane.showMessageDialog(rootPane, "Ringraziamento speciale ai miei amici che mi hanno aiutato a testare questo gioco!");
            }
        }
    }

    private class Trucchi extends KeyAdapter implements KeyListener {

        private String trucco = "";

        @Override
        public void keyPressed(KeyEvent e) {
            this.trucco = this.trucco + e.getKeyChar();
            if (e.getKeyChar() == 'r') {
                this.checkTrucco();
            }
        }

        public void checkTrucco() {
            char[] trick = this.trucco.toLowerCase().toCharArray();
            String controlla = "";
            if (trick.length >= 5) {
                for (int i = trick.length - 5; i < trick.length; i++) {
                    controlla = controlla + trick[i];
                }
                if (controlla.equals("ungar")) {
                    player.setSoldi(player.getSoldi()+1000);
                    jLabel17.setText(player.getSoldi()+"");
                    this.trucco = "";
                }
            }
        }
    }

    /** Creates new form Tavolo */
    public Tavolo(String title) {
        initComponents();
        this.setFocusable(true);
        addKeyListener(new Trucchi());
        addKeyListener(new Tasti());
        this.banco = new Banco();
        this.setTitle(title);
        this.jButton3.setVisible(false);
        this.jButton1.setEnabled(false);
        this.jButton2.setEnabled(false);
        char[] tit = title.toCharArray();
        String nome = "";
        for (int i = 12; i < title.length(); i++) {
            nome = nome + tit[i];
        }
        this.jLabel13.setText(nome);
        this.player= new Giocatore();
        this.jLabel17.setText(this.player.getSoldi() + "");
        this.jButton10.setEnabled(false);
        this.jPanel2.setVisible(false);
    }

    public void close() {
        System.exit(0);
    }

    public void drawCard() {
        Carta[] carte = this.banco.getCarte(0);
        ImageIcon[] card = new ImageIcon[5];
        for (int i = 0; i < carte.length; i++) {
            card[i] = new ImageIcon(getClass().getResource("/blackjack/graphics/images/" + carte[i].getNumero() + carte[i].getSeme() + this.estensione));
        }
        this.jLabel1.setIcon(card[0]);
        this.jLabel2.setIcon(card[1]);
        this.jLabel3.setIcon(card[2]);
        this.jLabel4.setIcon(card[3]);
        this.jLabel5.setIcon(card[4]);
        carte = this.banco.getCarte(1);
        card = new ImageIcon[5];
        for (int i = 0; i < carte.length; i++) {
            card[i] = new ImageIcon(getClass().getResource("/blackjack/graphics/images/" + carte[i].getNumero() + carte[i].getSeme() + this.estensione));
            if (carte[i].isCoperta()) {
                card[i] = new ImageIcon(getClass().getResource("/blackjack/graphics/images/back" + this.estensione));
            }
        }
        this.jLabel6.setIcon(card[0]);
        this.jLabel7.setIcon(card[1]);
        this.jLabel8.setIcon(card[2]);
        this.jLabel9.setIcon(card[3]);
        this.jLabel10.setIcon(card[4]);
        if (this.banco.isInsurancePossible() && !this.banco.isInsurance()) {
            JOptionPane.showMessageDialog(rootPane, "Puoi effettuare l'insurance, scommettendo la metà della puntata sul BlackJack del banco!");
            this.jButton3.setVisible(true);
        }
        this.jLabel14.setText(this.banco.getPunteggio(0) + "");
        this.jLabel12.setText(this.banco.getPunteggio(1) + "");
    }

    public void newGame() {
        this.player = new Giocatore();
        this.reset();
    }

    public void reset() {
        this.jButton4.setEnabled(true);
        this.jButton5.setEnabled(true);
        this.jButton6.setEnabled(true);
        this.jButton7.setEnabled(true);
        this.jButton8.setEnabled(true);
        this.jButton9.setEnabled(true);
        this.jButton3.setVisible(false);
        this.jButton10.setEnabled(false);
        this.jLabel19.setText("-");
        this.jLabel1.setIcon(null);
        this.jLabel2.setIcon(null);
        this.jLabel3.setIcon(null);
        this.jLabel4.setIcon(null);
        this.jLabel5.setIcon(null);
        this.jLabel6.setIcon(null);
        this.jLabel7.setIcon(null);
        this.jLabel8.setIcon(null);
        this.jLabel9.setIcon(null);
        this.jLabel10.setIcon(null);
        this.jLabel14.setText("0");
        this.jLabel12.setText("0");
        this.jLabel17.setText(this.player.getSoldi() + "");
        this.banco = new Banco();
        this.banco.setBet(0);
        this.jPanel2.setVisible(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jButton10 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel20 = new javax.swing.JLabel();
        jButton11 = new javax.swing.JButton();
        jLabel21 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        jPanel1.setBackground(new java.awt.Color(108, 219, 116));

        jLabel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jLabel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jLabel3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jLabel4.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jLabel5.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jLabel6.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jLabel7.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jLabel8.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jLabel9.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jLabel10.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jButton1.setText("Stai!");
        jButton1.setFocusable(false);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Carta!");
        jButton2.setFocusable(false);
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("Insurance!");
        jButton3.setFocusable(false);
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jLabel11.setText("Banco");

        jLabel12.setText("0");

        jLabel13.setText("jLabel13");

        jLabel14.setText("0");

        jLabel15.setText("Punta:");

        jLabel16.setText("Soldi:");

        jLabel17.setText("500");

        jButton4.setText("20");
        jButton4.setFocusable(false);
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setText("50");
        jButton5.setFocusable(false);
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton6.setText("100");
        jButton6.setFocusable(false);
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jButton7.setText("200");
        jButton7.setFocusable(false);
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        jButton8.setText("500");
        jButton8.setFocusable(false);
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });

        jButton9.setText("1000");
        jButton9.setFocusable(false);
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });

        jLabel18.setText("Bet:");

        jLabel19.setText("-");

        jButton10.setText("Punta!");
        jButton10.setFocusable(false);
        jButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton10ActionPerformed(evt);
            }
        });

        jPanel2.setBackground(new java.awt.Color(51, 94, 54));
        jPanel2.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED, new java.awt.Color(51, 94, 54), java.awt.Color.black, new java.awt.Color(51, 94, 54), new java.awt.Color(31, 19, 19)));

        jLabel20.setFont(new java.awt.Font("DejaVu Sans", 1, 24));
        jLabel20.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel20.setText("jLabel20");

        jButton11.setText("Continua a giocare!");
        jButton11.setFocusable(false);
        jButton11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton11ActionPerformed(evt);
            }
        });

        jLabel21.setText("Premere ESC per uscire, F1 per un nuovo gioco");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel20, javax.swing.GroupLayout.DEFAULT_SIZE, 301, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel21))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(90, 90, 90)
                        .addComponent(jButton11)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel20, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton11)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel21))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(50, 50, 50)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel15)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jButton6)
                                    .addComponent(jButton4)
                                    .addComponent(jButton8)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel16)
                                    .addComponent(jLabel18))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel19)
                                    .addComponent(jLabel17))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButton5)
                            .addComponent(jButton7)
                            .addComponent(jButton9)))
                    .addComponent(jButton10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jButton3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(16, 16, 16))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel13)
                            .addComponent(jLabel14))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 96, Short.MAX_VALUE)
                        .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel11)
                                .addGap(61, 61, 61))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel12, javax.swing.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                        .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(168, 168, 168))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(367, Short.MAX_VALUE)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(354, 354, 354))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 65, Short.MAX_VALUE)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(38, 38, 38)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(28, 28, 28)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton3)
                            .addComponent(jButton2)
                            .addComponent(jButton1))
                        .addContainerGap())
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel11)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel12)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 372, Short.MAX_VALUE)
                                .addComponent(jLabel13))
                            .addComponent(jButton10))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel14)
                            .addComponent(jLabel18)
                            .addComponent(jLabel19))
                        .addGap(31, 31, 31)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel16)
                            .addComponent(jLabel17))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel15)
                            .addComponent(jButton4)
                            .addComponent(jButton5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton6)
                            .addComponent(jButton7))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton8)
                            .addComponent(jButton9))
                        .addGap(9, 9, 9))))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        if (20 <= this.player.getSoldi()) {
            this.banco.setBet(this.banco.getBet()+20);
            this.player.setSoldi(this.player.getSoldi() - 20);
            this.jLabel17.setText(this.player.getSoldi() + "");
            this.jLabel19.setText(this.banco.getBet() + "");
            this.jButton10.setEnabled(true);
        }else{
            this.banco.setBet(this.banco.getBet()+this.player.getSoldi());
            this.player.setSoldi(0);
            this.jLabel17.setText(this.player.getSoldi()+"");
            this.jLabel19.setText(this.banco.getBet()+"");
            this.jButton10.setEnabled(true);
        }
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        if (50 <= this.player.getSoldi()) {
            this.banco.setBet(this.banco.getBet()+50);
            this.player.setSoldi(this.player.getSoldi() - 50);
            this.jLabel17.setText(this.player.getSoldi() + "");
            this.jLabel19.setText(this.banco.getBet() + "");
            this.jButton10.setEnabled(true);
        }else{
            this.banco.setBet(this.banco.getBet()+this.player.getSoldi());
            this.player.setSoldi(0);
            this.jLabel17.setText(this.player.getSoldi()+"");
            this.jLabel19.setText(this.banco.getBet()+"");
            this.jButton10.setEnabled(true);
        }
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        if (100 <= this.player.getSoldi()) {
            this.banco.setBet(this.banco.getBet()+100);
            this.player.setSoldi(this.player.getSoldi() - 100);
            this.jLabel17.setText(this.player.getSoldi() + "");
            this.jLabel19.setText(this.banco.getBet() + "");
            this.jButton10.setEnabled(true);
        }else{
            this.banco.setBet(this.banco.getBet()+this.player.getSoldi());
            this.player.setSoldi(0);
            this.jLabel17.setText(this.player.getSoldi()+"");
            this.jLabel19.setText(this.banco.getBet()+"");
            this.jButton10.setEnabled(true);
        }
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
        if (200 <= this.player.getSoldi()) {
            this.banco.setBet(this.banco.getBet()+200);
            this.player.setSoldi(this.player.getSoldi() - 200);
            this.jLabel17.setText(this.player.getSoldi() + "");
            this.jLabel19.setText(this.banco.getBet() + "");
            this.jButton10.setEnabled(true);
        }else{
            this.banco.setBet(this.banco.getBet()+this.player.getSoldi());
            this.player.setSoldi(0);
            this.jLabel17.setText(this.player.getSoldi()+"");
            this.jLabel19.setText(this.banco.getBet()+"");
            this.jButton10.setEnabled(true);
        }
    }//GEN-LAST:event_jButton7ActionPerformed

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
        if (500 <= this.player.getSoldi()) {
            this.banco.setBet(this.banco.getBet()+500);
            this.player.setSoldi(this.player.getSoldi() - 500);
            this.jLabel17.setText(this.player.getSoldi() + "");
            this.jLabel19.setText(this.banco.getBet() + "");
            this.jButton10.setEnabled(true);
        }else{
            this.banco.setBet(this.banco.getBet()+this.player.getSoldi());
            this.player.setSoldi(0);
            this.jLabel17.setText(this.player.getSoldi()+"");
            this.jLabel19.setText(this.banco.getBet()+"");
            this.jButton10.setEnabled(true);
        }
    }//GEN-LAST:event_jButton8ActionPerformed

    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
        if (1000 <= this.player.getSoldi()) {
            this.banco.setBet(this.banco.getBet()+1000);
            this.player.setSoldi(this.player.getSoldi() - 1000);
            this.jLabel17.setText(this.player.getSoldi() + "");
            this.jLabel19.setText(this.banco.getBet() + "");
            this.jButton10.setEnabled(true);
        }else{
            this.banco.setBet(this.banco.getBet()+this.player.getSoldi());
            this.player.setSoldi(0);
            this.jLabel17.setText(this.player.getSoldi()+"");
            this.jLabel19.setText(this.banco.getBet()+"");
            this.jButton10.setEnabled(true);
        }
    }//GEN-LAST:event_jButton9ActionPerformed

    private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
        this.jButton4.setEnabled(false);
        this.jButton5.setEnabled(false);
        this.jButton6.setEnabled(false);
        this.jButton7.setEnabled(false);
        this.jButton8.setEnabled(false);
        this.jButton9.setEnabled(false);
        this.jButton10.setEnabled(false);
        this.jButton1.setEnabled(true);
        this.jButton2.setEnabled(true);
        this.banco.start();
        this.drawCard();
        if (banco.isBlackJack(0)) {
            this.jButton1ActionPerformed(evt);
        }
    }//GEN-LAST:event_jButton10ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        this.banco.play();
        this.jButton1.setEnabled(false);
        this.jButton2.setEnabled(false);
        this.drawCard();
        this.player.setSoldi(this.player.getSoldi()+this.banco.pay());
        this.jPanel2.setVisible(true);
        String testo = "";
        if (this.banco.isWinner() || (this.banco.isBlackJack(0) && !this.banco.isBlackJack(1))) {
            testo = "Hai vinto " + this.banco.pay() + "!!!";
        } else {
            testo = "Mi dispiace hai perso!";
        }
        this.jLabel20.setText(testo);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        this.banco.carta(0);
        this.drawCard();
        if (this.banco.getPunteggio(0) > 21 || this.banco.getNumCarte(0) == 5) {
            this.jButton1ActionPerformed(evt);
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed
        this.reset();
        this.jPanel2.setVisible(false);
        if (this.player.getSoldi() == 0) {
            System.exit(0);
        }
    }//GEN-LAST:event_jButton11ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        if (!this.banco.isInsurance() && this.player.getSoldi() > this.banco.getBet() / 2) {
            this.player.setSoldi(this.player.getSoldi()-(this.banco.getBet()/2));
            this.jLabel17.setText(this.player.getSoldi() + "");
            this.banco.setIns(true);
            if (this.banco.isBlackJack(1)) {
                this.banco.setInsurance(true);
            }
        }
    }//GEN-LAST:event_jButton3ActionPerformed
    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton11;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    // End of variables declaration//GEN-END:variables
}
